package com.xinqi.modules.chat.chat.group.controller.admin;

import com.xinqi.common.base.constants.ServiceNameConstants;
import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.common.satoken.utils.LoginHelper;
import com.xinqi.modules.chat.chat.group.dto.req.AddUserGroupCreateAdminDTO;
import com.xinqi.modules.chat.chat.group.dto.req.ChatGroupUserAdminQueryDTO;
import com.xinqi.modules.chat.chat.group.dto.req.RemoveUserGroupAdminDTO;
import com.xinqi.modules.chat.chat.group.dto.req.SetUserGroupAdminDTO;
import com.xinqi.modules.chat.chat.group.dto.rsp.ChatGroupUserAdminResultDTO;
import com.xinqi.modules.chat.chat.group.service.ChatGroupUserService;
import com.xinqi.modules.chat.enums.group.GroupUserCommonEnum;
import com.xinqi.modules.chat.enums.group.GroupUserLeaderFlagEnum;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


/**
 * ADMIN -- 群组成员
 *
 * @version V1.0
 * @Title:
 * @ClassName: com.xinqi.modules.chat.chat.group.controller.admin.ChatGroupUserAdminController.java
 * @Description:
 * @Copyright 星齐科技（云南）有限公司 - Powered By 技术部
 * @author: yyzhen
 * @date: 2023/8/22 11:29
 */
@RestController
@RequestMapping("/admin/chat-group-user")
@RequiredArgsConstructor
public class ChatGroupUserAdminController {
    private final ChatGroupUserService chatGroupUserService;

    @Operation(summary = "加群方式-枚举列表")
    @GetMapping("/common")
    public R<List<Map<String, String>>> commonList() {
        return R.data(GroupUserCommonEnum.getSelectList());
    }

    @Operation(summary = "用户标识-枚举列表")
    @GetMapping("/leaderFlag")
    public R<List<Map<String, String>>> leaderFlagList() {
        return R.data(GroupUserLeaderFlagEnum.getSelectList());
    }

    @Operation(summary = "查询成员列表")
    @GetMapping("/page")
    public R<PageInfo<ChatGroupUserAdminResultDTO>> pageAdmin(ChatGroupUserAdminQueryDTO dto) {
        return R.data(chatGroupUserService.pageAdmin(dto, dto));
    }

    @Operation(summary = "添加群成员")
    @PostMapping("/add")
    //@Log(title = ServiceNameConstants.XQ_CHAT + " -- 添加群成员", businessType = BusinessType.INSERT, operatorType = OperatorType.MANAGE)
    public R<Boolean> addAdmin(@Validated @RequestBody AddUserGroupCreateAdminDTO dto) {
        return R.data(chatGroupUserService.addAdmin(LoginHelper.getXqLoginUser(), dto));
    }

    @Operation(summary = "移除群成员")
    @PostMapping("/remove")
    //@Log(title = ServiceNameConstants.XQ_CHAT + " -- 移除群成员", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    public R<Boolean> removeAdmin(@Validated @RequestBody RemoveUserGroupAdminDTO dto) {
        return R.data(chatGroupUserService.removeAdmin(LoginHelper.getXqLoginUser(), dto));
    }

    @Operation(summary = "设为群主")
    @PostMapping("/set-leader")
    //@Log(title = ServiceNameConstants.XQ_CHAT + " -- 设为群主", businessType = BusinessType.GRANT, operatorType = OperatorType.MANAGE)
    public R<Boolean> setLeaderAdmin(@Validated @RequestBody SetUserGroupAdminDTO dto) {
        return R.data(chatGroupUserService.setLeaderAdmin(LoginHelper.getXqLoginUser(), dto));
    }

}
